<{include file="top_v2.html"}>
</head>
<body>
<div id="wrap" class="pt buy-page-2">
    <div class="header">
        订单信息
        <a href="javascript:window.history.back();" class="back"></a>
    </div>
    <div class="tabs">
        <{if $isPhone}>
            <a no="1" id="tab_to_1" href="javascript:void(0);">到店</a>
        <{/if}>
        <{if $isCard}>
            <a no="3" id="tab_to_3" href="javascript:void(0);">电子券</a>
        <{/if}>
        <{if $isExpress}>
            <a no="2" id="tab_to_2" href="javascript:void(0);">快递</a>
        <{/if}>
    </div>



    <!--自提-->
    <form class="container" id="tab_mo_1">
        <input type="hidden" name="deliverType" value="<{$DELIVERY_PHONE}>" />
        <div class="common">
            <div class="ui-item">
                <label>用户姓名:</label>
                <input type="text" name="realname" placeholder="请输入真实姓名" value="<{$userInfo['realName']}>"/>
            </div>

            <div class="ui-item">
                <label>联系电话:</label>
                <input type="tel" name="phone" placeholder="请输入联系电话" value="<{$userInfo['bindPhone']}>">
            </div>
        </div>
        <div class="section-2 address">
            <div class="ui-item">
                <label>提货地址:</label>
                <div class="address-box">
                    <textarea id="textarea1" name="address" readonly style="height: auto;overflow: visible"><{$data.pickAddress}></textarea>
                </div>
            </div>
        </div>

        <{if $data.nowPrice gt 0 or $data.point gt 0}>
        <p class="title">支付信息</p>
        <div class="section-3">
            <{if $data.point gt 0}>
            <div class="ui-item">
                <span class="ui-label">所需积分(拥有<{$userInfo['userPoint']}>积分):</span>
                <span class="red"><{$data.point}>积分</span>
            </div>
            <{/if}>
            <{if $data.nowPrice gt 0}>
                <div class="ui-item">
                    <span class="ui-label">所需金额:</span>
                    <span class="red"><{$data.nowPrice}>元</span>
                </div>
            <{/if}>
        </div>
        <{/if}>


        <input type="hidden" name="id" value="<{$data.id}>"/>
        <div class="btn-group">
            <a href="javascript:void(0);" class="btn-1">提交信息</a>
        </div>
    </form>
    <!--快递-->
    <form class="container" id="tab_mo_2">
        <input type="hidden" name="deliverType" value="<{$DELIVERY_SEND}>" />
        <div class="info" style="display: block;">注: 快递寄送服务仅限<strong><{$data.deliverArea}></strong>地区</div>
        <div class="common">
            <div class="ui-item">
                <label>用户姓名:</label>
                <input type="text" name="realname" placeholder="请输入真实姓名" value="<{$userInfo['realName']}>"/>
            </div>

            <div class="ui-item">
                <label>联系电话:</label>
                <input type="tel" name="phone" placeholder="请输入联系电话" value="<{$userInfo['bindPhone']}>">
            </div>
        </div>
        <div class="section-2 address">
            <div class="ui-item">
                <label>收货地址:</label>
                <div class="address-box">
                    <textarea id="textarea2" name="address"><{if $userInfo.address != "..."}><{$userInfo['address']}><{/if}></textarea>
                </div>
            </div>
        </div>

        <p class="title">支付信息</p>

        <div class="section-3">
            <{if $data.point gt 0}>
            <div class="ui-item">
                <span class="ui-label">所需积分(拥有<{$userInfo['userPoint']}>积分):</span>
                <span class="red"><{$data.point}>积分</span>
            </div>
            <{/if}>
            <{if $data.nowPrice gt 0}>
            <div class="ui-item">
                <span class="ui-label">产品费用:</span>
                <span class="red"><{$data.nowPrice}>元</span>
            </div>
            <{/if}>
            <div class="ui-item">
                <span class="ui-label">快递费用:</span>
                <span class="red"><{if $data.deliverPay > 0}><{$data.deliverPay}>元<{else}>包邮<{/if}></span>
            </div>
        </div>
        <input type="hidden" name="id" value="<{$data.id}>"/>
        <div class="btn-group">
            <a href="javascript:void(0);" class="btn-2">提交信息</a>
        </div>
    </form>
    <!--电子券-->
    <form class="container" id="tab_mo_3">
        <input type="hidden" name="deliverType" value="<{$DELIVERY_CARD}>" />
        <div class="common">
            <div class="ui-item">
                <label>用户姓名:</label>
                <input type="text" name="realname" placeholder="请输入真实姓名" value="<{$userInfo['realName']}>"/>
            </div>

            <div class="ui-item">
                <label>电子券:</label>
                <input type="text" readonly value="<{$cardName}>"/>
            </div>
        </div>

        <{if strlen($data.pickAddress) gt 2}>
        <div class="section-2 address">
            <div class="ui-item">
                <label>提货地址:</label>
                <div class="address-box">
                    <textarea readonly name="address" style="height: auto;overflow: visible"><{$data.pickAddress}></textarea>
                </div>
            </div>
        </div>
        <{/if}>

        <p class="title">支付信息</p>
        <div class="section-3">
            <{if $data.point gt 0}>
            <div class="ui-item">
                <span class="ui-label">所需积分(拥有<{$userInfo['userPoint']}>积分):</span>
                <span class="red"><{$data.point}>积分</span>
            </div>
            <{/if}>
            <{if $data.nowPrice gt 0}>
            <div class="ui-item">
                <span class="ui-label">所需金额:</span>
                <span class="red"><{$data.nowPrice}>元</span>
            </div>
            <{/if}>
        </div>


        <input type="hidden" name="id" value="<{$data.id}>"/>
        <div class="btn-group">
            <a href="javascript:void(0);" class="btn-3">提交信息</a>
        </div>
    </form>
</div>


</body>
</html>

<script>


    $(function(){
        $(".tabs a").click(function(){
            var isOn = $(this).hasClass("on");
            if(isOn){
                return;
            }
            var idx = $(this).attr('no');

            $(this).addClass("on").siblings().removeClass("on");
            $(".container").hide();
            $("#tab_mo_"+idx).show();
        })
        $('.tabs a').eq(0).click();


        $(".btn-1").click(function(){
            submitInfo(1);
        })

        $(".btn-2").click(function(){
            submitInfo(2);
        })
        $(".btn-3").click(function(){
            submitInfo(3);
        })


        var text2 = document.getElementById("textarea2");
        autoTextarea(text2);

    })



    function submitInfo(e){
        var param = $("#tab_mo_"+e).serialize();
        load();
        $.ajax({
            url:"<{U('PointMall/doExchange')}>",
            dataType:"json",
            data:param,
            type:"POST",
            success:function(data){
                console.log(data);
                layer.closeAll();
                if (data.status==0) {
                    if(typeof data.orderStatus!='undefined' && data.orderStatus==3){
                        window.location.href=data.jumpUrl;
                    }else{
                        tip(data.msg);
                        window.history.go(-1);
                    }
                }else{
                    tip(data.msg);
                }
            },
            error:function(data){
                tip('异常');
            }
        });
    }

</script>